import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'password_generator.dart';
import 'generated/l10n.dart';

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  platformIsWindow() {
    if (kIsWeb) {
      return false;
    }
    if (Platform.isWindows) {
      return true;
    }
    if (Platform.isMacOS) {
      return true;
    }
    if (Platform.isLinux) {
      return true;
    }

    return false;
  }

  @override
  Widget build(BuildContext context) {
    return kIsWeb
        ? _WebHomePage()
        : platformIsWindow()
            ? _WindowHomePage()
            : _MobileHomePage();
  }
}

class _WindowHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: Center(
        child: PasswordGenerator(isWindow: true),
      ),
    );
  }
}

class _WebHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Scaffold(
      appBar: null,
      body: Center(
        child: PasswordGenerator(isWindow: size.width > size.height),
      ),
    );
  }
}

class _MobileHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(S.of(context).password_generator),
      ),
      body: Center(
        child: PasswordGenerator(isWindow: false),
      ),
    );
  }
}
